const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
    return sequelize.define(
        'sys_user_role',
        {
            id: {
                autoIncrement: true,
                type: DataTypes.BIGINT,
                allowNull: false,
                primaryKey: true,
                comment: '关联ID',
            },
            user_id: {
                type: DataTypes.BIGINT,
                allowNull: false,
                comment: '用户ID',
                references: {
                    model: 'sys_user',
                    key: 'id',
                },
            },
            role_id: {
                type: DataTypes.BIGINT,
                allowNull: false,
                comment: '角色ID',
                references: {
                    model: 'sys_role',
                    key: 'id',
                },
            },
            create_time: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
            },
        },
        {
            sequelize,
            tableName: 'sys_user_role',
            timestamps: false,
            indexes: [
                {
                    name: 'PRIMARY',
                    unique: true,
                    using: 'BTREE',
                    fields: [{ name: 'id' }],
                },
                {
                    name: 'uk_user_role',
                    unique: true,
                    using: 'BTREE',
                    fields: [{ name: 'user_id' }, { name: 'role_id' }],
                },
                {
                    name: 'role_id',
                    using: 'BTREE',
                    fields: [{ name: 'role_id' }],
                },
            ],
        },
    );
};
